import { updateUserById, DeleteUserById } from "@/api/userApi";
export default {
  data() {
    return {
      // 搜索框
      searchStatus: "",
      searchNickname: "",
      // 修改弹窗
      centerDialogVisible: false,
      fromUpdate: {
        nickname: "",
        username: "",
        status: "",
      },
      // status: "",
      // 分页工具
      page: 1,
      pageSize: 10,
    };
  },
  methods: {
    // 饿了么组件开始

    // 搜索框
    selectGO() {
      // const nickname = this.searchNickname;
      // const status = this.searchStatus;
      // const page = this.Page;
      // const pageSize = this.pageSize;
      this.$store.dispatch("getUsers", {
        nickname: this.searchNickname || undefined,
        status: this.searchStatus || undefined,
        page: this.page,
        pageSize: this.pageSize,
      });
    },

    // 弹窗操作
    fromUpdateById(row) {
      // this.status = row.status; // 状态
      console.log(this.fromUpdate.status);

      this.centerDialogVisible = true;
      this.fromUpdate = row;
      if (row.status === 1) {
        this.fromUpdate.status = "正常";
      }
      if (row.status === 0) {
        this.fromUpdate.status = "禁用";
      }
      console.log(this.fromUpdate.status);
    },
    // 取消操作
    updateUserError() {
      this.centerDialogVisible = false;
      this.$message.warning("取消操作");
      this.selectGO();
    },
    // 表格操作
    updateUser() {
      console.log(this.fromUpdate);

      updateUserById(this.fromUpdate).then((resp) => {
        if (resp.data.msg != "success") {
          this.$message.error("未知错误");
          return false;
        }
        // console.log(resp);
        this.$message.success("修改成功");
        this.selectGO();
        this.centerDialogVisible = false;
      });
    },
    deleteUser(row) {
      DeleteUserById(row.id).then((resp) => {
        if (resp.data.msg != "success") {
          this.$message.error("未知错误");
          return false;
        }
        this.$message.success("删除成功");
        this.selectGO();
      });
    },
    // 分页工具
    handleSizeChange(val) {
      this.pageSize = val;
      this.selectGO();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.selectGO();
    },
  },
  mounted() {
    this.selectGO();
  },
  created: function () {},
};
